{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 離散型確率分布"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1次元の離散型確率分布"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-07T04:43:23.771523Z",
     "start_time": "2018-08-07T04:43:23.575758Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "%precision 3\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1次元の離散型確率分布の定義"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-07T04:43:23.775156Z",
     "start_time": "2018-08-07T04:43:23.772847Z"
    }
   },
   "outputs": [],
   "source": [
    "x_set = np.array([1, 2, 3, 4, 5, 6])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-07T04:43:23.779344Z",
     "start_time": "2018-08-07T04:43:23.776685Z"
    }
   },
   "outputs": [],
   "source": [
    "def f(x):\n",
    "    if x in x_set:\n",
    "        return x / 21\n",
    "    else:\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-07T04:43:23.783380Z",
     "start_time": "2018-08-07T04:43:23.780556Z"
    }
   },
   "outputs": [],
   "source": [
    "X = [x_set, f]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-07T04:43:23.795835Z",
     "start_time": "2018-08-07T04:43:23.784515Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1: 0.048, 2: 0.095, 3: 0.143, 4: 0.190, 5: 0.238, 6: 0.286}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 確率p_kを求める\n",
    "prob = np.array([f(x_k) for x_k in x_set])\n",
    "# x_kとp_kの対応を辞書型にして表示\n",
    "dict(zip(x_set, prob))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-07T04:43:23.911086Z",
     "start_time": "2018-08-07T04:43:23.796855Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmgAAAF1CAYAAABcTxaRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAGQhJREFUeJzt3X+0ZWdZH/DvY4MTSWwihTRlEC5OrAsKMTHXZqghgYVgS3ABiVppLauVdFJoVURXjdpla9pG1qrW0roUJ6CxWnH5K/gjWKlpgkxNpvllJCErGsxNxLEtGXSUFILo0z/OGXtnuDNzgdn3vHPu57PWXTn73Pfd5znPvbn55t1n713dHQAAxvFZiy4AAIAjCWgAAIMR0AAABiOgAQAMRkADABiMgAYAMJhJAlrNXF9Vd1fVtccY84yquqWq9lXVL1TVGZuZBwCw7KZaQdud5PQkq0n2VNXTNxhzRpKruvuSJP8nyfM2OQ8AYKlNFdAuSnJLkvOT7Ety4dEDuvvBJM+oqvuSnNHd+zczDwBg2Z020X7PSvJoknOS3Drf/iTd/Z6qen6SvVW1ezPzqmpPkj1J8uQnP/miXbt2TVD+uD7xiU/ktNOm+rFtb3o7Lf2djt5OS3+ns916+773ve+x7n7aZsZO1ZVDSXYkeX9mq2IPHz2gqp6T5IPd/SdV9a4kl21mXnfvTbI3SVZXV/vOO++c6C2MaW1tLSsrK4suYynp7bT0dzp6Oy39nc52621VPbLZsVMd4rwrycXd/VCSS5Pcs8GYVyb5qv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q+pnknxxZmHshswOqa4/ceGlSZ6X2WHOWzfx2sA2J6ABp6qzMlsNe3KSjxxrUHe/Jclbkr84/Pg1Sf7D8XZcVV8wH/e3jtrXu6rqs5P8UpJvSvLWqrouyT+Yj093/1lVrZ/2R0l+MckHMjvcecTqHcBGBDTglNTdv19Vb09yc1X9WZK/lNnftNOSvLC7/3j9+Kp6XpK3Jfm+7j74STucjdmZ5J8k+dtJXtPdH93gdT9eVQ8n+aEkn5vk25O87hiHWJ+S5Hvnjw9/Bi5V9Vh3/+wG4wGSJNXdi64BYHJV9bYk7+zuXz7OmLMzuyTGO7v7E5/Ba70qs0Ocr+jur/p09wNsXwIaAMBgXGYDAGAwAhoAwGAENACAwQhoAACDEdAAAAbz/wAdZWwf1AMK1wAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize=(10, 6))\n",
    "ax = fig.add_subplot(111)\n",
    "ax.bar(x_set, prob)\n",
    "ax.set_xlabel('とりうる値')\n",
    "ax.set_ylabel('確率')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-07T04:43:23.915961Z",
     "start_time": "2018-08-07T04:43:23.912531Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.all(prob >= 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-07T04:43:23.920725Z",
     "start_time": "2018-08-07T04:43:23.917448Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.000"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(prob)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-07T04:43:23.924982Z",
     "start_time": "2018-08-07T04:43:23.922208Z"
    }
   },
   "outputs": [],
   "source": [
    "def F(x):\n",
    "    return np.sum([f(x_k) for x_k in x_set if x_k <= x])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-07T04:43:23.935804Z",
     "start_time": "2018-08-07T04:43:23.926354Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.286"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "F(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.697148Z",
     "start_time": "2018-08-06T11:25:17.692368Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{5: 0.048, 7: 0.095, 9: 0.143, 11: 0.190, 13: 0.238, 15: 0.286}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_set = np.array([2 * x_k + 3 for x_k in x_set])\n",
    "prob = np.array([f(x_k) for x_k in x_set])\n",
    "dict(zip(y_set, prob))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1次元の離散型確率分布の指標"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 平均"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.701479Z",
     "start_time": "2018-08-06T11:25:17.698316Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.333"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum([x_k * f(x_k) for x_k in x_set])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.737094Z",
     "start_time": "2018-08-06T11:25:17.702621Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.333"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sample = np.random.choice(x_set, int(1e6), p=prob)\n",
    "np.mean(sample)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.740722Z",
     "start_time": "2018-08-06T11:25:17.738306Z"
    }
   },
   "outputs": [],
   "source": [
    "def E(X, g=lambda x: x):\n",
    "    x_set, f = X\n",
    "    return np.sum([g(x_k) * f(x_k) for x_k in x_set])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.745675Z",
     "start_time": "2018-08-06T11:25:17.741807Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.333"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "E(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.750269Z",
     "start_time": "2018-08-06T11:25:17.746911Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11.667"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "E(X, g=lambda x: 2*x + 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.754447Z",
     "start_time": "2018-08-06T11:25:17.751181Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11.667"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 * E(X) + 3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 分散"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.759274Z",
     "start_time": "2018-08-06T11:25:17.755396Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.222"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mean = E(X)\n",
    "np.sum([(x_k-mean)**2 * f(x_k) for x_k in x_set])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.763465Z",
     "start_time": "2018-08-06T11:25:17.760361Z"
    }
   },
   "outputs": [],
   "source": [
    "def V(X, g=lambda x: x):\n",
    "    x_set, f = X\n",
    "    mean = E(X, g)\n",
    "    return np.sum([(g(x_k)-mean)**2 * f(x_k) for x_k in x_set])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.768386Z",
     "start_time": "2018-08-06T11:25:17.764699Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.222"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "V(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.773328Z",
     "start_time": "2018-08-06T11:25:17.769350Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8.889"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "V(X, lambda x: 2*x + 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.778674Z",
     "start_time": "2018-08-06T11:25:17.774588Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8.889"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2**2 * V(X)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2次元の離散型確率分布"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2次元の離散型確率分布の定義"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.783029Z",
     "start_time": "2018-08-06T11:25:17.780291Z"
    }
   },
   "outputs": [],
   "source": [
    "x_set = np.arange(2, 13)\n",
    "y_set = np.arange(1, 7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.788516Z",
     "start_time": "2018-08-06T11:25:17.784611Z"
    }
   },
   "outputs": [],
   "source": [
    "def f_XY(x, y):\n",
    "    if 1 <= y <=6 and 1 <= x - y <= 6:\n",
    "        return y * (x-y) / 441\n",
    "    else:\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.793487Z",
     "start_time": "2018-08-06T11:25:17.789901Z"
    }
   },
   "outputs": [],
   "source": [
    "XY = [x_set, y_set, f_XY]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.932737Z",
     "start_time": "2018-08-06T11:25:17.794592Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAioAAAHWCAYAAABZiKJMAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcm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bFQkWSpM5r106dJjn1I0mSWstERZKkrit6ezKtiYokSWotExVJkvqgRU88bpKJiiRJai0TFUmSOq6A6ukaFQsVSZK6rsqpH0mSpGUZuDXJgSQ3rdFmLsnuJA8luXH42suS3J3kI0m+Z6N+TFQkSeqBGUz97AA2AduBw0luqarDK9pcCzwMvBl4PMltwI3AHcADwLuB/7leJyYqkiRpHJcC9wDbgL3AJeu02QHlIaqKAAABOElEQVTsAy467rWtwOeSvGS9TkxUJEnqg+mvUdkMPAmcC+wZ3q/WZhE4D3hkeL/82ueBw8P7p9fqZOKFylN8fvEP6t1PTLofSdJknf6lsx5Bp7xymp09xefv+oN695aGP3ZTkoXj7ndV1a7j7o8Ac8DHGKQkn1jlM44AW4CDwHXD+yPAhQxSmJ8d3q9p4oVKVb180n1IknQqq6rvmEG3+4HrqurOJFcAt6/RZiuDxGUbcGj42pcBHwfOqqo10xRwjYokSRrPPuCcJA8AD66ykBZgN3D1sO1tVXUU2AX8SwbFy69s1Emqp4+FliRJ05PkSuBu4MKqamzJh4WKJEk6acPdOxcAj1bVc419roWKJElqK9eoSJKk1rJQkSRJrWWhIkmSWstCRZIktZaFiiRJai0LFUmS1Fr/H6QvExcoerw3AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 720x576 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "prob = np.array([[f_XY(x_i, y_j) for y_j in y_set]\n",
    "                 for x_i in x_set])\n",
    "\n",
    "fig = plt.figure(figsize=(10, 8))\n",
    "ax = fig.add_subplot(111)\n",
    "\n",
    "c = ax.pcolor(prob)\n",
    "ax.set_xticks(np.arange(prob.shape[1]) + 0.5, minor=False)\n",
    "ax.set_yticks(np.arange(prob.shape[0]) + 0.5, minor=False)\n",
    "ax.set_xticklabels(np.arange(1, 7), minor=False)\n",
    "ax.set_yticklabels(np.arange(2, 13), minor=False)\n",
    "# y軸を下が大きい数字になるように、上下逆転させる\n",
    "ax.invert_yaxis()\n",
    "# x軸の目盛りをグラフ上側に表示\n",
    "ax.xaxis.tick_top()\n",
    "fig.colorbar(c, ax=ax)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.937185Z",
     "start_time": "2018-08-06T11:25:17.934188Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.all(prob >= 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.942400Z",
     "start_time": "2018-08-06T11:25:17.938424Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.000"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(prob)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.948437Z",
     "start_time": "2018-08-06T11:25:17.943951Z"
    }
   },
   "outputs": [],
   "source": [
    "def f_X(x):\n",
    "    return np.sum([f_XY(x, y_k) for y_k in y_set])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.953066Z",
     "start_time": "2018-08-06T11:25:17.949777Z"
    }
   },
   "outputs": [],
   "source": [
    "def f_Y(y):\n",
    "    return np.sum([f_XY(x_k, y) for x_k in x_set])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:17.957088Z",
     "start_time": "2018-08-06T11:25:17.954497Z"
    }
   },
   "outputs": [],
   "source": [
    "X = [x_set, f_X]\n",
    "Y = [y_set, f_Y]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.155840Z",
     "start_time": "2018-08-06T11:25:17.958366Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAtwAAAEVCAYAAADTpjKIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3XucZVV55//P16BNpJ1GQgixTShtciPKQOiEJkEgQ4wZ0YmAuSdemcZLnBhjIurvl4nMSMwk/vIzmqiNGswkJOMlEBUdLwSiHekONwkIg7ZSYCQXaJRERmA0z/yxd+np6lNdp7rPOlWn6vN+vfrF2bvW3s+zq0+v87DOXnulqpAkSZLUxkOWOwFJkiRpNbPgliRJkhqy4JYkSZIasuCWJEmSGrLgliRJkhqy4JYkSZIasuDWVEnyrUm+kGR9kocn2Z3kyEnEPYBj1/X/TZJvHqH9o5K8eX/jSdJKkeTXBvuzJH+e5NkTiGufrRXFgltTpar+HvhL4OnATwBXVNU/zP08yfcneUeSm5LcluSjSV6VZMPgeZKcluTuJNf0fz6d5LMD27cmuWjgkPOTvL4/9k+SfCLJPye5pX99W5LfmZ9vkqOAa5ME+B7gI0kOWuQyzwb+9378eiRppbkIeFqSdUkOBU4G3jH3Q/tsrRWLvYmklejNwCv616+e25nkHODZwC8CJwHfCvxGv++jSU6rqi8MnOd9VfWs/thnAYdX1e/026cBzxpo+zzgPUl+oap+rm9zOfC8qvp0kp8Bjh2S6/8D/H51K0zd3B9z/kD+JPkG4NqBY44F/jbJJ4ac75yqumb4r0WSVpaq+qckHwPOAA4DLqmq+8A+W2uLBbem0YeB3+9ffwS6URK6DvaUqvrfSZ4LbK+qrwJvSbKRriP9lcETJXkF8GTgCOChSZ4G/BPwe4PtquqrfQf9wMDufwPc1b/+xnk/I8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omwf39UsUnzRv3zcCFwFfAV4C3ED3Pwx/nGR3Ve0EzuLrS9MeD+yk66yPxk5b0pSrquuTfGqgr7bf1ppiwa2p0s8sfwrw/cDV/ejDV/ufHQV8uaru7rcfCmwE7uq31wP/CfjhqvrXRUJ9gK4znRvN+A7guhFSPBa4dd6+HwbeCdwJ/ABwW1XdkeSdwL+l66QvovsqdHBS0BOBx9F9PXnlCLElaSUbvGXDfltrigW3ps2zgXdX1f1J3kH3NeA/JjkB+FXg9wCSPAz4/4E/qarqj91AN+LxcOBL+wpSVa8DXtef65HAT/bnW1CSx/btfnDeud7f5/Ne4JeANyW5APiFvv3cqM7gYV8E3gN8hu5ryj1GaSRpytlva03J19/T0nRK8m10X0d+GPhd4HfovqJ8B/DfquqrA21fADyTbnTlG+j+p/Mg4AlV9c9Dzv04uhn1b6uqbQvE30g3gfPHgF+oqv+1QLs3Ad8FPAK4A/jPVXXjwM+fRjdS8gyGz694Q1W9a8h+SZoq9ttaayy4ter0j2maraqvjOFcbwEurar37aPNoXSPgrr0QGIOdNxPqaqn7+95JGna2G9rtbPgliRJkhrysYCSJElSQxbckiRJUkMW3JIkSVJDFtySJElSQxbckiRJUkMW3JIkSVJD/xcVaGMgDcbigwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 864x288 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "prob_x = np.array([f_X(x_k) for x_k in x_set])\n",
    "prob_y = np.array([f_Y(y_k) for y_k in y_set])\n",
    "\n",
    "fig = plt.figure(figsize=(12, 4))\n",
    "ax1 = fig.add_subplot(121)\n",
    "ax2 = fig.add_subplot(122)\n",
    "\n",
    "ax1.bar(x_set, prob_x)\n",
    "ax1.set_title('Xの周辺分布')\n",
    "ax1.set_xlabel('Xのとりうる値')\n",
    "ax1.set_ylabel('確率')\n",
    "ax1.set_xticks(x_set)\n",
    "\n",
    "ax2.bar(y_set, prob_y)\n",
    "ax2.set_title('Yの周辺分布')\n",
    "ax2.set_xlabel('Yのとりうる値')\n",
    "ax2.set_ylabel('確率')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2次元の離散型確率分布の指標"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.160597Z",
     "start_time": "2018-08-06T11:25:18.157222Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8.667"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum([x_i * f_XY(x_i, y_j) for x_i in x_set for y_j in y_set])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.165682Z",
     "start_time": "2018-08-06T11:25:18.161951Z"
    }
   },
   "outputs": [],
   "source": [
    "def E(XY, g):\n",
    "    x_set, y_set, f_XY = XY\n",
    "    return np.sum([g(x_i, y_j) * f_XY(x_i, y_j)\n",
    "                   for x_i in x_set for y_j in y_set])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.171317Z",
     "start_time": "2018-08-06T11:25:18.166922Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8.667"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mean_X = E(XY, lambda x, y: x)\n",
    "mean_X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.176800Z",
     "start_time": "2018-08-06T11:25:18.172606Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.333"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mean_Y = E(XY, lambda x, y: y)\n",
    "mean_Y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.181411Z",
     "start_time": "2018-08-06T11:25:18.179270Z"
    }
   },
   "outputs": [],
   "source": [
    "a, b = 2, 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.188112Z",
     "start_time": "2018-08-06T11:25:18.182684Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "30.333"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "E(XY, lambda x, y: a*x + b*y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.192651Z",
     "start_time": "2018-08-06T11:25:18.189335Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "30.333"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a * mean_X + b * mean_Y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.198072Z",
     "start_time": "2018-08-06T11:25:18.193879Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.444"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum([(x_i-mean_X)**2 * f_XY(x_i, y_j)\n",
    "       for x_i in x_set for y_j in y_set])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.202487Z",
     "start_time": "2018-08-06T11:25:18.199151Z"
    }
   },
   "outputs": [],
   "source": [
    "def V(XY, g):\n",
    "    x_set, y_set, f_XY = XY\n",
    "    mean = E(XY, g)\n",
    "    return np.sum([(g(x_i, y_j)-mean)**2 * f_XY(x_i, y_j)\n",
    "                   for x_i in x_set for y_j in y_set])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.208121Z",
     "start_time": "2018-08-06T11:25:18.203578Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.444"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "var_X = V(XY, g=lambda x, y: x)\n",
    "var_X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.214829Z",
     "start_time": "2018-08-06T11:25:18.209153Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.222"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "var_Y = V(XY, g=lambda x, y: y)\n",
    "var_Y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.220141Z",
     "start_time": "2018-08-06T11:25:18.215853Z"
    }
   },
   "outputs": [],
   "source": [
    "def Cov(XY):\n",
    "    x_set, y_set, f_XY = XY\n",
    "    mean_X = E(XY, lambda x, y: x)\n",
    "    mean_Y = E(XY, lambda x, y: y)\n",
    "    return np.sum([(x_i-mean_X) * (y_j-mean_Y) * f_XY(x_i, y_j)\n",
    "                    for x_i in x_set for y_j in y_set])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.226352Z",
     "start_time": "2018-08-06T11:25:18.221226Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.222"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cov_xy = Cov(XY)\n",
    "cov_xy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.232830Z",
     "start_time": "2018-08-06T11:25:18.227964Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "64.444"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "V(XY, lambda x, y: a*x + b*y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.238309Z",
     "start_time": "2018-08-06T11:25:18.234241Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "64.444"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a**2 * var_X + b**2 * var_Y + 2*a*b * cov_xy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T11:25:18.243046Z",
     "start_time": "2018-08-06T11:25:18.239669Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.707"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cov_xy / np.sqrt(var_X * var_Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "toc_cell": false,
   "toc_position": {
    "height": "911px",
    "left": "0px",
    "right": "1493px",
    "top": "107px",
    "width": "212px"
   },
   "toc_section_display": "block",
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
